package com.heima.wemedia.admin;

import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.wemedia.dtos.ChannelDto;
import com.heima.model.wemedia.pojos.WmChannel;
import com.heima.wemedia.service.WmChannelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * @Author: JW
 * @Description: TODO
 * @DateTime: 2022-02-18 20:30
 **/
@RestController
@RequestMapping("/api/v1/channel")
public class ChannelController {

    @Autowired
    private WmChannelService wmChannelService;

    /**
     * @Author: JW
     * @Description:  TODO 删除频道
     * @Date: 20:57 2022-02-18
     * @Param: [id]
     * @return: com.heima.model.common.dtos.ResponseResult
    **/
    @GetMapping("/del/{id}")
    public ResponseResult delete(@PathVariable Integer id){

        wmChannelService.removeById(id);

        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);

    }


    /**
     * @Author: JW
     * @Description:  TODO
     * @Date: 20:33 2022-02-18
     * @Param: []
     * @return: com.heima.model.common.dtos.ResponseResult
    **/
    @PostMapping("/list")
    public PageResponseResult find(@RequestBody ChannelDto channelDto){

        return wmChannelService.find(channelDto);
    }


    /**
     * @Author: JW
     * @Description:  TODO 保存频道
     * @Date: 20:54 2022-02-18
     * @Param: [wmChannel]
     * @return: com.heima.model.common.dtos.ResponseResult
    **/
    @PostMapping("/save")
    public ResponseResult save(@RequestBody WmChannel wmChannel){

        wmChannel.setCreatedTime(new Date());
        wmChannelService.save(wmChannel);

        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }

    /**
     * @Author: JW
     * @Description:  TODO 修改
     * @Date: 20:56 2022-02-18
     * @Param:
     * @return:
    **/
    @PostMapping("/update")
    public ResponseResult update(@RequestBody WmChannel wmChannel){


        wmChannel.setCreatedTime(new Date());
        wmChannelService.updateById(wmChannel);


        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }
}
